﻿using System;
using System.Media;
using System.Windows.Forms;
using DoMain;

namespace TMIS
{
    public partial class LogIn : Form
    {

        public bool Closeflag = true;

        public LogIn()
        {
            InitializeComponent();
        }

        private void btn_login_Click(object sender, EventArgs e)
        {
            Login();
        }

        private void btn_logout_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void Login()
        {
            var name = textBox_name.Text;
            var password = textBox_password.Text;
            var logDomain = new LoginDomain();
            if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(password))
            {
                logDomain.LogInDone(false);
                MessageBox.Show(@"用户名或密码为空，请检查。", @"提示");
            }
            else
            {
                var message = logDomain.LogIn(name, password);
                if (!string.IsNullOrEmpty(message))
                {
                    logDomain.LogInDone(false);
                    MessageBox.Show(message);
                }
                else
                {
                    Closeflag = false;
                    logDomain.LogInDone(true, name);
                    Close();
                }
            }
        }
    }
}